package cn.sstir.hackathon.controller;

import cn.sgst.tool.common.response.Response;
import cn.sstir.hackathon.core.ExportType;
import cn.sstir.hackathon.core.page.PageResult;
import cn.sstir.hackathon.core.search.CompanyQuery;
import cn.sstir.hackathon.core.search.PatentQuery;
import cn.sstir.hackathon.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author: fli
 * @email: fli@sstir.cn
 * @date: 2020/1/16 16:44
 */
@Controller
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @ResponseBody
    @GetMapping("/search")
    public Response search(CompanyQuery companyQuery) throws Exception{
        PageResult pageResult = companyService.search(companyQuery);
        return Response.success(pageResult);
    }

    /**
     * 导出excel
     *
     * @author fli
     * @date 2020/1/17 0:52
     */
    @GetMapping("/export/excel")
    public void exportExcel(HttpServletResponse response, @RequestParam List<String> columns, CompanyQuery companyQuery) throws Exception{
        companyService.export(response,columns,companyQuery,ExportType.excel);
    }


    /**
     * 导出csv
     *
     * @author fli
     * @date 2020/1/17 0:52
     */
    @GetMapping("/export/csv")
    public void exportCsv(HttpServletResponse response, @RequestParam List<String> columns,CompanyQuery companyQuery) throws Exception{
        companyService.export(response,columns,companyQuery,ExportType.csv);
    }

    /**
     * 导出csv
     *
     * @author fli
     * @date 2020/1/17 0:52
     */
    @GetMapping("/export/tsv")
    public void exportTsv(HttpServletResponse response, @RequestParam List<String> columns,CompanyQuery companyQuery) throws Exception{
        companyService.export(response,columns,companyQuery,ExportType.tsv);
    }
}
